<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <!-- import CSS -->
  <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
  <style>
    .el-page-header__content{
      color: white;
    }
  </style>
</head>
<body>
<div id="app">
  <el-page-header style="background-color: #0096dc;
  color: white;line-height: 60px"
                  @back="goBack" content="添加第二轮播图页面">
  </el-page-header>
  <!--上传组件开始-->
  <el-upload
          action="/upload"
          name="picFile"
          limit="1"
          list-type="picture-card"
          :on-success="handleSuccess"
          :on-preview="handlePictureCardPreview"
          :on-remove="handleRemove">
    <i class="el-icon-plus"></i>
  </el-upload>
  <el-dialog :visible.sync="dialogVisible">
    <img width="100%" :src="dialogImageUrl" alt="">
  </el-dialog>
  <!--上传组件结束-->
  <el-button type="success" @click="upload()">上传轮播图</el-button>
</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
 let v = new Vue({
    el: '#app',
    data: function() {
      return {
        dialogImageUrl: '',
        dialogVisible: false,
        url:""
      }
    },
   methods:{
      upload(){
        if (v.url==""){
          v.$message.error("请选择上传的图片!");
          return;
        }
        axios.get("/bannerTwo/insert?url="+v.url).then(function () {
          alert("上传完成!");
          location.href = "/admin.html?currentIndex=5-1";//回到后台管理页面
        })
      },
     goBack() {
       console.log('go back');
       //返回上一页面
       history.back();
     },
     handleSuccess(response,file,fileList){
        v.url=response;
     },
     handleRemove(file, fileList) {
        //发出删除图片的请求
       axios.get("/remove?url="+v.url).then(function () {
         console.log("删除服务器图片完成!");
         v.url="";
       })

       console.log(file, fileList);
     },
     handlePictureCardPreview(file) {
       this.dialogImageUrl = file.url;
       this.dialogVisible = true;
     }
   }
  })
</script>
</html>